package ca.nfb.media.nfbPlayer.views
{
	
	import ca.nfb.media.nfbPlayer.ComModule;
	import ca.nfb.media.nfbPlayer.NFBPyroBrew;
	import ca.nfb.media.nfbPlayer.ui.ToolTip;
	import ca.turbulent.media.Pyro;
	import ca.turbulent.media.events.PyroEvent;
	import ca.turbulent.media.events.StatusUpdateEvent;	
	import ca.turbulent.text.SuperText;
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.StageDisplayState;
	import flash.events.Event;
	import flash.events.FullScreenEvent;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.text.AntiAliasType;
	import flash.text.CSMSettings;
	import flash.text.Font;
	import flash.text.FontStyle;
	import flash.text.FontType;
	import flash.text.GridFitType;
	import flash.text.StaticText;
	import flash.text.StyleSheet;
	import flash.text.TextColorType;
	import flash.text.TextDisplayMode;
	import flash.text.TextExtent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	import flash.text.TextLineMetrics;
	import flash.text.TextRenderer;
	import flash.text.TextSnapshot;
	
	
	public class ControlBar extends NFBPlayerView
	{
		private var isDraggingVolume		:Boolean = false;
		private var progressRectangle		:Rectangle;
		private var requiredWidth			:Number;
		private var sliderOut				:Boolean = false; 	
		private var timeCheck				:Number = 0;
		private var subtitlesTF				:TextFormat;
		private var volumeSliderOpened		:Boolean = false;
		
		public var buttonsEnabledArray		:Array = new Array();
		public var hasBuyButton				:Boolean = false;
		public var hasInfosButton			:Boolean = false;
		public var bookmarksView			:BookmarksView;	
		public var subtitles				:TextField = new TextField();
		
		public var subtitlesOn				:Boolean = false;
		
		

		public function ControlBar(initWidth:Number)
		{
			super();
			requiredWidth = initWidth;
			
		}
		
		override protected function addedToStage(evt:Event):void
		{
			initializeControlBar();
			registerStageEvents();
			var localWidth:Number = core.requestedSizes.width;
			
			overlay_mc.width = localWidth;
			background_mc.width = localWidth;
			mask_mc.width = localWidth;
			positionHorizontals();
		}
		
		override protected function checkLang():void
		{
			switch(ComModule.getLang())
			{
				case "EN":
				optionsButton_mc.standardQuality_mc.gotoAndStop(1);
				optionsButton_mc.lowQuality_mc.gotoAndStop(1);
				optionsButton_mc.highQuality_mc.gotoAndStop(1);
				break;
				
				case "FR":
				optionsButton_mc.standardQuality_mc.gotoAndStop(2);
				optionsButton_mc.lowQuality_mc.gotoAndStop(2);
				optionsButton_mc.highQuality_mc.gotoAndStop(2);
				break;
			}
		}
		
		private function initializeControlBar():void
		{
			this.buttonMode 				= false;
			this.mouseEnabled 				= false;
			
			if (core.embeddedMode)
				this.hasInfosButton = true;
			
			progressRectangle 				= new Rectangle(14.2, 16.2, 0, 90);
			lockUI(true, [volumeSlider_mc]);
			
			background_mc.width = requiredWidth;
			
			subtitlesTF = new TextFormat(core.mainFont.fontName, 13, 0xFFFFFF);
			subtitlesTF.align = TextFormatAlign.CENTER;
			subtitles.defaultTextFormat = subtitlesTF;
			subtitles.wordWrap = true;
			subtitles.multiline = true;
			subtitles.x = 1;
			subtitles.y = -30;
			subtitles.width = background_mc.width-2;
			subtitles.height = 34;
			subtitles.gridFitType = GridFitType.PIXEL;
			subtitles.antiAliasType = AntiAliasType.ADVANCED;
			subtitles.selectable = false;
			subtitles.embedFonts = true;
			subtitles.thickness = -100;
			subtitles.sharpness = 250;
			subtitles.mouseEnabled = false;
			addChild(subtitles);
			
			menuButton_mc.visible = false;
			volumeSlider_mc.visible = false;
			
			MovieClip(playPauseButton_mc.pauseIcon_mc).visible = false;
			MovieClip(playPauseButton_mc.playIcon_mc).visible = true;
			MovieClip(playPauseButton_mc.bufferingIcon_mc).visible = false;
			
			for(var i:int=0; i<this.numChildren; ++i)
			{
				var localMovie = this.getChildAt(i);
				
				if(localMovie is MovieClip)
				{
					if(localMovie.name.indexOf("Button_mc") != -1)
					{
						localMovie.gotoAndStop(1);
						localMovie.alpha 			= .7;
						localMovie.buttonMode 		= true;
						localMovie.addEventListener(MouseEvent.ROLL_OVER, controlButtonHandler, false, 0, true);
						localMovie.addEventListener(MouseEvent.ROLL_OUT, controlButtonHandler, false, 0, true);
						localMovie.addEventListener(MouseEvent.CLICK, controlButtonHandler, false, 0, true);
					}
				}
			} 
			
			lockUI(false, [movableBars_mc.backgroundBar_mc]);
			
			movableBars_mc.backgroundBar_mc.addEventListener(MouseEvent.ROLL_OVER, movableBarsHandler, false, 0, true);
			movableBars_mc.backgroundBar_mc.addEventListener(MouseEvent.ROLL_OUT, movableBarsHandler, false, 0, true);
			
			movableBars_mc.bufferingBar_mc.addEventListener(MouseEvent.ROLL_OVER, movableBarsHandler, false, 0, true);
			movableBars_mc.bufferingBar_mc.addEventListener(MouseEvent.ROLL_OUT, movableBarsHandler, false, 0, true);
			
			movableBars_mc.progressBar_mc.addEventListener(MouseEvent.ROLL_OVER, movableBarsHandler, false, 0, true);
			movableBars_mc.progressBar_mc.addEventListener(MouseEvent.ROLL_OUT, movableBarsHandler, false, 0, true);
			
			
			movableBars_mc.progressBar_mc.useHandCursor = true;
			movableBars_mc.bufferingBar_mc.useHandCursor = true;
			movableBars_mc.progressBar_mc.buttonMode = true;
			movableBars_mc.bufferingBar_mc.buttonMode = true;
			movableBars_mc.seekBar_mc.buttonMode = true;
			movableBars_mc.seekBar_mc.useHandCursor = true;
			ComModule.getInstance().addEventListener(ComModule.FILE_URL_RECEIVED_EVENT, newFileURLReceived, false, 0, true);
			
			player.addEventListener(NFBPyroBrew.STREAM_QUALITY_CHANGE, setCorrectSpeedLabel, false, 0, true);
			player.addEventListener(PyroEvent.SEEKED, wasSeeked, false, 0, true);
			player.addEventListener(PyroEvent.BUFFER_EMPTY, bufferEmptied, false, 0, true);
			player.addEventListener(PyroEvent.BUFFER_FULL, bufferFilled, false, 0, true);
			
			setCorrectSpeedLabel();
			
			infosButton_mc.visible = false;
			cartButton_mc.visible = false;
			closeCaptionsButton_mc.visible = false;
			descAudioButton_mc.visible = false;
			middleVDivider_mc.visible = false;
			
			setOptionals();
			
			
			player.registerProgressCallback({name:this.name, funct:onProgress});
			player.startProgressEngine();

			mapVolumeSlider();
			
			bookmarksView = new BookmarksView();
			bookmarksView.x = movableBars_mc.x;
			bookmarksView.y = movableBars_mc.y;
			addChild(bookmarksView);
			
			ToolTip.addToolTipLabelElement("pause", "Pause", "Pause");
			ToolTip.addToolTipLabelElement("play", "Play", "Jouer");
			ToolTip.addToolTipLabelElement("infosButton_mc", "More info", "En savoir plus");
			ToolTip.addToolTipLabelElement("optionsButton_mc", "Connection speed options", "Vitesses de connexion à Internet");
			ToolTip.addToolTipLabelElement("closeCaptionsButton_mc", "Close captions", "Sous-titre");
			ToolTip.addToolTipLabelElement("descAudioButton_mc", "Audio description", "Description audio");
			ToolTip.addToolTipLabelElement("sharingButton_mc", "Share this film", "Partager ce film");
			ToolTip.addToolTipLabelElement("cartButton_mc", "Buy now", "Achetez maintenant");
			ToolTip.addToolTipLabelElement("volumeButton_mc", "Volume", "Volume");
			ToolTip.addToolTipLabelElement("fullscreenButton_mc", "Toggle fullscreen", "Basculer en mode plein écran");
			ToolTip.addToolTipLabelElement("smallLogoButton_mc", "http://www.nfb.ca", "http://www.onf.ca");
			ToolTip.addToolTipLabelElement("menuButton_mc", "Close and back to controls", "Fermer les sous-titres et voir les contrôles"); 
			
			core.tabManager.clearFromFocus([this, playPauseButton_mc, infosButton_mc, optionsButton_mc, closeCaptionsButton_mc, descAudioButton_mc, sharingButton_mc, cartButton_mc, volumeButton_mc, fullscreenButton_mc, smallLogoButton_mc, menuButton_mc]);
			core.screenReaderManager.addAccess(playPauseButton_mc, "Toggle pause on video.", "Mettre la vidéo en pause ou bien jouer la vidéo.");
			core.screenReaderManager.addAccess(infosButton_mc, "More info", "En savoir plus");
			core.screenReaderManager.addAccess(optionsButton_mc, "Connection speed options", "Vitesses de connexion à Internet");
			core.screenReaderManager.addAccess(closeCaptionsButton_mc, "Close captions", "Sous-titre");
			core.screenReaderManager.addAccess(descAudioButton_mc, "Audio description", "Description audio");
			core.screenReaderManager.addAccess(sharingButton_mc, "Share this film", "Partager ce film");
			core.screenReaderManager.addAccess(cartButton_mc, "Buy now", "Achetez maintenant");
			core.screenReaderManager.addAccess(volumeButton_mc, "Volume", "Volume");
			core.screenReaderManager.addAccess(fullscreenButton_mc, "Toggle fullscreen", "Basculer en mode plein écran");
			core.screenReaderManager.addAccess(smallLogoButton_mc, "http://www.nfb.ca", "http://www.onf.ca" );
			core.screenReaderManager.addAccess(menuButton_mc, "Close and back to controls", "Fermer les sous-titres et voir les contrôles" );
			
			this.setProperties([fullscreenButton_mc], {mouseEnabled:false, alpha:.3});
			this.setProperties([movableBars_mc], {mouseEnabled:false, mouseChildren:false});
			
		}
		
		public function bufferEmptied(evt:PyroEvent):void
		{
			
			if (player.status != Pyro.STATUS_PENDING)
			{
				if (core.currentState != NFBPlayer.END_PLAYLIST_STATE)
				{
					MovieClip(playPauseButton_mc.pauseIcon_mc).visible = false;
					MovieClip(playPauseButton_mc.playIcon_mc).visible = false;
					MovieClip(playPauseButton_mc.bufferingIcon_mc).visible = true;
					
					lockButtons(true);
									
					if (!MovieClip(playPauseButton_mc).hasEventListener(Event.ENTER_FRAME))
						MovieClip(playPauseButton_mc).addEventListener(Event.ENTER_FRAME, rotateArrow, false, 0, true);
				}	
			}
		}
		
		public function bufferFilled(evt:PyroEvent):void
		{
			if (player.status != Pyro.STATUS_PENDING)
			{
				if (core.currentState != NFBPlayer.END_PLAYLIST_STATE)
				{
					if (player.status == Pyro.STATUS_PAUSED)
					{
						MovieClip(playPauseButton_mc.pauseIcon_mc).visible = false;
						MovieClip(playPauseButton_mc.playIcon_mc).visible = true;
					}
					else
					{
						MovieClip(playPauseButton_mc.pauseIcon_mc).visible = true;
						MovieClip(playPauseButton_mc.playIcon_mc).visible = false;
					}
					MovieClip(playPauseButton_mc.bufferingIcon_mc).visible = false;
					
					lockButtons(false);
									
					if (MovieClip(playPauseButton_mc).hasEventListener(Event.ENTER_FRAME))
						MovieClip(playPauseButton_mc).removeEventListener(Event.ENTER_FRAME, rotateArrow);
				}	
			}
		}
		
		public function setCorrectSpeedLabel(evt:Event=null):void
		{
			optionsButton_mc.lowQuality_mc.visible = false;
			optionsButton_mc.standardQuality_mc.visible = false;
			optionsButton_mc.highQuality_mc.visible = false;
			
			switch(player.streamQuality)
			{
				case Pyro.CONNECTION_SPEED_HIGH:
				optionsButton_mc.highQuality_mc.visible = true;
				break;
				
				case Pyro.CONNECTION_SPEED_MEDIUM:
				default:
				optionsButton_mc.standardQuality_mc.visible = true;
				break;
				
				case Pyro.CONNECTION_SPEED_LOW:
				optionsButton_mc.lowQuality_mc.visible = true;
				break;
			}
		}
		
		
		
		private function newFileURLReceived(evt:Event):void
		{
			setTrackOptions();
			this.timeCheck = 0;			
		}
		
		public function setTrackOptions():void
		{
			
			if (!ComModule.getInstance().latestMovieHasCC)
				this.setProperties([closeCaptionsButton_mc], {mouseEnabled:false, alpha:.3});
			else
				this.setProperties([closeCaptionsButton_mc], {mouseEnabled:true, visible:true, useHandCursor:true, buttonMode:true, alpha:.7});
				
			if (!ComModule.getInstance().latestMovieHasDV)
				this.setProperties([descAudioButton_mc], {mouseEnabled:false, alpha:.3});
			else
				this.setProperties([descAudioButton_mc], {mouseEnabled:true, visible:true, useHandCursor:true, buttonMode:true, alpha:.7});
				
			if (core.embeddedMode && core.enableMoreInfosButton)
				this.setProperties([infosButton_mc], {mouseEnabled:true, visible:true, useHandCursor:true, buttonMode:true, alpha:.7});
			else
				this.setProperties([infosButton_mc], {mouseEnabled:false, visible:false, useHandCursor:false, buttonMode:false, alpha:.3});	
						
			if (core.enableSpeedOptionsButton)
				this.setProperties([optionsButton_mc], {mouseEnabled:true, useHandCursor:true, buttonMode:true, alpha:.7});				
			
			if (core.isSmaller)
			{
				infosButton_mc.visible = false;
				optionsButton_mc.visible = false;
				leftVDivider_mc.visible = false;
				sharingButton_mc.visible = false;
				descAudioButton_mc.visible = false;
			}
			
			switch(player.streamType)
			{
				case Pyro.STREAM_TYPE_PROGRESSIVE:
				movableBars_mc.bufferingBar_mc.addEventListener(MouseEvent.MOUSE_DOWN, seekTo, false, 0, true);
				movableBars_mc.progressBar_mc.addEventListener(MouseEvent.MOUSE_DOWN, seekTo, false, 0, true);
				break;
				
				case Pyro.STREAM_TYPE_TRUE_STREAM:
				case Pyro.STREAM_TYPE_PROXIED_PROGRESSIVE:
				movableBars_mc.bufferingBar_mc.addEventListener(MouseEvent.MOUSE_DOWN, seekTo, false, 0, true);
				movableBars_mc.progressBar_mc.addEventListener(MouseEvent.MOUSE_DOWN, seekTo, false, 0, true);
				movableBars_mc.seekBar_mc.addEventListener(MouseEvent.MOUSE_DOWN, seekTo, false, 0, true);
				break;
				
			}
		
		}
		
		public function setOptionals():void
		{
			if (!core.enableVolumeButton)
				this.setProperties([volumeButton_mc], {mouseEnabled:false, alpha:.3});
			
			if (!core.enablePlayButton)
				this.setProperties([playPauseButton_mc], {mouseEnabled:false, alpha:.3});	
				
			if (!player.useFullScreen)
				this.setProperties([fullscreenButton_mc], {mouseEnabled:false, alpha:.3});	
			
			if (core.isSmaller)
				this.leftVDivider_mc.visible = false;			
			
			if (!core.enableMoreInfosButton)
			{
				infosButton_mc.visible = false;
				this.hasInfosButton = false;
			}
			else
			{
				if (core.embeddedMode)
				{
					if (!core.isSmaller)
					{
						infosButton_mc.visible = true;
						this.hasInfosButton = true;
					}
					else
					{
						infosButton_mc.visible = false;
						this.hasInfosButton = false;
					}
				
				}
				else
				{
					infosButton_mc.visible = false;
					this.hasInfosButton = false;
				}
			}
			
			if (!core.enableSpeedOptionsButton || (!ComModule.getInstance().latestMovieHasLowSpeed && !ComModule.getInstance().latestMovieHasNormalSpeed && !ComModule.getInstance().latestMovieHasExtremeSpeed) || ComModule.getInstance().packageFromURL)
			{
				if (!core.isSmaller)
					this.setProperties([optionsButton_mc], {mouseEnabled:false, mouseChildren:false, useHandCursor:false, alpha:.3});	
				else	
					this.optionsButton_mc.visible = false;
			}
			else
			{
				if (core.isSmaller)
				{
					this.optionsButton_mc.visible = false;
				}	
			}
			
			if (!core.enableDescriptiveAudioButton)
			{
				this.descAudioButton_mc.visible = false;
			}	
			else
			{
				if (!core.isSmaller)
				{
					if (player.fileType == NFBPyroBrew.FILE_TYPE_DV || player.streamType == NFBPyroBrew.FILE_TYPE_CCDV)
					{
						
						this.descAudioButton_mc.visible = true;
						middleVDivider_mc.visible = true;
					}
					else
					{
						if (player.fileType == NFBPyroBrew.FILE_TYPE_NORMAL)
						{
							if (ComModule.getInstance().latestMovieHasDV)
							{
								this.descAudioButton_mc.visible = true;
								middleVDivider_mc.visible = true;
							}
							else
							{
								this.descAudioButton_mc.visible = false;
								middleVDivider_mc.visible = false;
							}
						}
						else if (player.fileType == NFBPyroBrew.FILE_TYPE_CC)
						{
							if (ComModule.getInstance().latestMovieHasCCDV)
							{
								this.descAudioButton_mc.visible = true;
								middleVDivider_mc.visible = true;
							}	
							else
							{
								this.descAudioButton_mc.visible = false;	
								middleVDivider_mc.visible = false;
							}
						}
					}
				}
				else
				{
					this.descAudioButton_mc.visible = false;
					middleVDivider_mc.visible = false;
				}		
			}
			
			if (!core.enableCloseCaptionsButton)
			{
				this.closeCaptionsButton_mc.visible = false;
			}
			else
			{
			
				if (player.fileType == NFBPyroBrew.FILE_TYPE_CC || player.streamType == NFBPyroBrew.FILE_TYPE_CCDV)
				{
			
					this.closeCaptionsButton_mc.visible = true;
				}
				else
				{
					if (!core.isSmaller)
					{
						if (player.fileType == NFBPyroBrew.FILE_TYPE_NORMAL)
						{
							if (ComModule.getInstance().latestMovieHasCC)
								this.closeCaptionsButton_mc.visible = true;
							else
								this.closeCaptionsButton_mc.visible = false;
						}
						else if (player.fileType == NFBPyroBrew.FILE_TYPE_DV)
						{
							if (ComModule.getInstance().latestMovieHasCCDV)
								this.closeCaptionsButton_mc.visible = true;
							else
								this.closeCaptionsButton_mc.visible = false;	
						}
					}
					else
					{
						this.closeCaptionsButton_mc.visible = false;
					}	
				}
			}

			if (!core.enableSharingButton)
			{
				this.sharingButton_mc.visible = false;
			}
			else
			{
				if (!core.isSmaller)
					this.sharingButton_mc.visible = true;
				else
					this.sharingButton_mc.visible = false;
			}
			
			this.cartButton_mc.visible = false;
			this.hasBuyButton = false;	
			
			smallLogoButton_mc.visible = false;
	
		}
		
		private function controlButtonHandler(e:MouseEvent):void
		{
			switch(e.type)
			{
				case "rollOver":
					switch(e.currentTarget)
					{
						case playPauseButton_mc:
							playPauseButton_mc.background_mc.gotoAndStop(2);
							playPauseButton_mc.alpha = 1;
							
							if (player.status == Pyro.STATUS_PLAYING)
								core.toolTip.showToolTip(ToolTip.getLabel('pause'), playPauseButton_mc);
							else if (player.status == Pyro.STATUS_PAUSED)
								core.toolTip.showToolTip(ToolTip.getLabel('play'), playPauseButton_mc); 
						break;
						
						default:
							e.target.alpha = 1;
							core.toolTip.showToolTip(ToolTip.getLabel(DisplayObject(e.target).name), DisplayObject(e.target));
						break;
					}	
				break;
				
				case "rollOut":
					core.toolTip.hideToolTip();
					switch(e.currentTarget)
					{
						case playPauseButton_mc:
							playPauseButton_mc.background_mc.gotoAndStop(1);
						break;
						
						default:
							e.target.alpha = .7;
						break;
					}
				break;
				
				case "click":
					switch(e.currentTarget.name)
					{
						case "volumeButton_mc":
							volumeButtonMD();
						break;
						
						case "infosButton_mc":
							core.setCurrentState(NFBPlayer.MORE_INFOS_STATE);
						break;
						
						case "optionsButton_mc":
							if (core.currentState == NFBPlayer.END_PLAYLIST_STATE)
								core.moreInfoView.endPlaylistOn = true;
							else
								core.moreInfoView.endPlaylistOn = false;
							
							core.embeddedWelcomeView.visible = false;
							core.setCurrentState(NFBPlayer.OPTIONS_STATE);
							
						break;
						
						case "descAudioButton_mc":
							core.setCurrentState(NFBPlayer.DEFAULT_STATE);
							core.toggleAudioDescription();
							core.embeddedWelcomeView.visible = false;
						
						break;
						
						case "closeCaptionsButton_mc":
							if (core.player.fileType == NFBPyroBrew.FILE_TYPE_CC || core.player.fileType == NFBPyroBrew.FILE_TYPE_CCDV)
							{
								if (this.subtitlesOn)
								{
									this.closeSubtitles();
								}
								else
								{
									this.openSubtitles();
								}	
							}
							else
							{
								core.setCurrentState(NFBPlayer.DEFAULT_STATE);
								core.toggleCloseCaptions();	
							}	
							core.embeddedWelcomeView.visible = false;
						break;
						
						case "sharingButton_mc":
							if (core.currentState == NFBPlayer.END_PLAYLIST_STATE)
								core.sharingView.endPlaylistOn = true;
							else
								core.sharingView.endPlaylistOn = false;
								
							core.setCurrentState(NFBPlayer.SHARING_STATE);
						break;
						
						case "cartButton_mc":
						break;
						
						case "smallLogoButton_mc":
						break;
						
						case "playPauseButton_mc":
							if (core.currentState == NFBPlayer.PREVIEW_IMAGE_STATE)
							{
								core.previewImage.hideImage();
								core.setCurrentState(NFBPlayer.DEFAULT_STATE);
								player.play(ComModule.getInstance().latestFileURL);
							}
							else
							{
								if (core.currentState == NFBPlayer.END_PLAYLIST_STATE)
								{
									if (player.streamType == Pyro.STREAM_TYPE_PROXIED_PROGRESSIVE)
									{
										if (player.timeOffset > 0)
										{
											var tURL:String = ComModule.getInstance().latestFileURL;
											var fileURL:String="";
											if (tURL.indexOf("?start=") > 0)
											{	
												fileURL = tURL.substring(0, tURL.indexOf("?"));
											}
											else
											{
												fileURL = tURL;
											}
											
											fileURL += "?start=0"
											movableBars_mc.progressBar_mc.width = 0;
											player.play(fileURL);
										}
										else
										{
											player.play();
										}
									}
									else
									{
										player.play();
									}
									core.setCurrentState(NFBPlayer.DEFAULT_STATE);
									
									// player.play(ComModule.getInstance().latestFileURL);
								}
								else
								{
									player.togglePause();
								}
							}
							if (player.status == Pyro.STATUS_PLAYING)
								core.toolTip.showToolTip(ToolTip.getLabel('pause'), playPauseButton_mc);
							else if (player.status == Pyro.STATUS_PAUSED)
								core.toolTip.showToolTip(ToolTip.getLabel('play'), playPauseButton_mc); 
								
						break;
						
						case "fullscreenButton_mc":
						player.toggleFullScreen();
						break;
						
						case "menuButton_mc":
							this.closeSubtitles();
						break;
					}
				break;
			} 
			
		}
		
		public function enableCartButton():void
		{
		}
		
		public function disableCartButton():void
		{
			this.setProperties([cartButton_mc], {mouseEnabled:false, alpha:0});
		}
		
		public function mapVolumeSlider():void
		{
			if (player.volume > 0)
			{
				if (player.volume > 1)
					player.volume = 1;
					
				volumeSlider_mc.sliderHandler_mc.gotoAndStop(1);
			}
			else
			{
				if (player.volume <= 0)
					player.volume = 0;
				
				volumeSlider_mc.sliderHandler_mc.gotoAndStop(2); 	
			}	
			
			var sliderFactor:Number = player.volume * Number(progressRectangle.height);
			MovieClip(volumeSlider_mc.sliderHandler_mc).y = progressRectangle.y+progressRectangle.height+(-1*sliderFactor);
			
			var directY:Number = Math.floor(Number(progressRectangle.bottom) - MovieClip(volumeSlider_mc.sliderHandler_mc).y);
			volumeSlider_mc.volumeMask_mc.height = directY;
		}
	
		public function closeSubtitles():void
		{
			playPauseButton_mc.y = 5;
			volumeButton_mc.y = 26;
			fullscreenButton_mc.y = 25;
			leftVDivider_mc.y = 19;
			infosButton_mc.y = 25;
			optionsButton_mc.y = 28;
			descAudioButton_mc.y = 26;
			closeCaptionsButton_mc.y = 24;
			sharingButton_mc.y = 25;
			cartButton_mc.y = 24;
			rightVDivider_mc.y = 19;
			smallLogoButton_mc.y = 23;
			hDivider_mc.y = 17;
			middleVDivider_mc.y = 19;
			leftTime_txt.y = 2.5;
			rightTime_txt.y = 2.5;
			movableBars_mc.y = 5;
			
			subtitles.y = 70;
			
			subtitles.htmlText = "";
			menuButton_mc.y = 50;
			bookmarksView.visible = true;
			menuButton_mc.visible = false;
			subtitlesOn = false;
			
			player.height = stage.stageHeight-37;
			background_mc.y = 0;
			background_mc.height = 37;
			
		}
		
		public function openSubtitles():void
		{
			playPauseButton_mc.y = volumeButton_mc.y = fullscreenButton_mc.y = leftVDivider_mc.y = infosButton_mc.y = optionsButton_mc.y = descAudioButton_mc.y = 
			closeCaptionsButton_mc.y = sharingButton_mc.y = cartButton_mc.y = rightVDivider_mc.y = smallLogoButton_mc.y = 70 ;
			hDivider_mc.y = 75;
			middleVDivider_mc.y = 75;
			leftTime_txt.y = 26.5;
			rightTime_txt.y = 26.5;
			movableBars_mc.y = 29;
			if (stage.displayState == StageDisplayState.FULL_SCREEN)
			{
				subtitles.y = -38;
				subtitles.x = 1;
				subtitles.height = 70;
				background_mc.y = -40;
				background_mc.height = 87;
				player.height = stage.stageHeight-87;
				
			}
			else
			{
				
				subtitles.y = 2;
				subtitles.x = 1;
				subtitles.height = 34;
				background_mc.y = 0;
				background_mc.height = 37;
				player.height = stage.stageHeight-37;
				
			}	
			
			menuButton_mc.y = 25;
			menuButton_mc.visible = true;
			subtitlesOn = true;
			closeVolumeSlider();
			bookmarksView.visible = false;
		}
		
		public function wasSeeked(evt:Event):void
		{
			subtitles.htmlText = "";
		}
		
		
		private function closeVolumeSlider():void
		{
			volumeSliderOpened = false;
			sliderOut = false;
			MovieClip(volumeSlider_mc.sliderHandler_mc).stopDrag();
			volumeSlider_mc.visible = false;
			lockUI(false, [volumeButton_mc]);
			lockUI(true, [volumeSlider_mc]);
			
			if (stage.hasEventListener(MouseEvent.MOUSE_UP))
				stage.removeEventListener(MouseEvent.MOUSE_UP, sliderHandlerUp);
			
			if (stage.hasEventListener(MouseEvent.MOUSE_MOVE))
				stage.removeEventListener(MouseEvent.MOUSE_MOVE, sliderMoved);
		}
		
		private function positionHorizontals():void
		{
			var tabX:Number = 0;
			if (stage.displayState == StageDisplayState.FULL_SCREEN)
				tabX = 20;
			
			subtitles.width = background_mc.width-2;
			
			smallLogoButton_mc.x = stage.stageWidth - (40+tabX);
			rightVDivider_mc.x = stage.stageWidth - (53+tabX);
			rightTime_txt.x = stage.stageWidth - (40+tabX);
			fullscreenButton_mc.x = stage.stageWidth - (79+tabX);
			volumeSlider_mc.x = stage.stageWidth - (114+tabX);
			volumeButton_mc.x = stage.stageWidth - (109+tabX);
			infosButton_mc.x = stage.stageWidth - (143+tabX);
			cartButton_mc.x = stage.stageWidth - (170+tabX);
			
			
			hDivider_mc.width = stage.stageWidth - (hDivider_mc.x + 8); 
			
			var movableGap:Number = rightTime_txt.x - (leftTime_txt.x+leftTime_txt.width)-5; 
			movableBars_mc.progressMask_mc.asset_mc.width = movableGap;
			movableBars_mc.progressBar_mc.asset_mc.width = movableGap;
			movableBars_mc.bufferingBar_mc.asset_mc.width = movableGap;
			movableBars_mc.backgroundBar_mc.asset_mc.width = movableGap;
			movableBars_mc.seekBar_mc.width = movableGap;
			movableBars_mc.paleStroke_mc.asset_mc.width = movableGap-1;
			movableBars_mc.darkOutline_mc.asset_mc.width = movableGap-1;
			
			if (core.isSmaller)
			{
				infosButton_mc.visible = false;
				optionsButton_mc.visible = false;
				middleVDivider_mc.visible = false;
				sharingButton_mc.visible = false;
				descAudioButton_mc.visible = false;
				closeCaptionsButton_mc.visible = false;
				leftVDivider_mc.visible = false;
			}
			else
			{
				if (core.enableMoreInfosButton && this.hasInfosButton)
					infosButton_mc.visible = true;
					
				if (core.enableSharingButton)
					sharingButton_mc.visible = true;
					
				if (core.enableSpeedOptionsButton)
					optionsButton_mc.visible = true;
				
				if (core.enableCloseCaptionsButton)
					closeCaptionsButton_mc.visible = true;
				
				if (core.enableDescriptiveAudioButton)
					descAudioButton_mc.visible = true;
							
				if (sharingButton_mc.visible && (descAudioButton_mc.visible || optionsButton_mc.visible))
					middleVDivider_mc.visible = true;
			}
			
			if (sharingButton_mc.visible)
			{
				middleVDivider_mc.x = sharingButton_mc.x + 26;
				if (closeCaptionsButton_mc.visible)
				{
					closeCaptionsButton_mc.x = middleVDivider_mc.x + 12;
					if (descAudioButton_mc.visible)
						descAudioButton_mc.x = closeCaptionsButton_mc.x + 28;
				}
				else
				{
					if (descAudioButton_mc.visible)
						descAudioButton_mc.x = middleVDivider_mc.x + 12;
				}	
				
				leftVDivider_mc.visible = true;	
					
			}	
				
			// subtitles.width = stage.stageWidth-tabX;
			
			// trace("position h"+this.x + " , " + this.y + " , " + volumeButton_mc.x+" , " + volumeButton_mc.y);
		}
		
		private function seekTo(evt:MouseEvent=null):void
		{
			var totalWidth:Number = movableBars_mc.backgroundBar_mc.width;
			var localX:Number;
			localX = MovieClip(movableBars_mc.backgroundBar_mc).mouseX
			var pointInTime:Number = (localX * player.duration) / totalWidth;
			
			if (pointInTime - 1 < 0)
				pointInTime = 0;
			else
				pointInTime -= 1;
			
			
			if (evt.currentTarget == movableBars_mc.seekBar_mc)
			{
				switch(player.streamType)
				{
					case Pyro.STREAM_TYPE_PROGRESSIVE:
					break;
					
					case Pyro.STREAM_TYPE_PROXIED_PROGRESSIVE:
					var tURL:String = ComModule.getInstance().latestFileURL;
					var fileURL:String="";
					
					if (tURL.indexOf("?start=") > 0)
						fileURL = tURL.substring(0, tURL.indexOf("?"));
					else
						fileURL = tURL;
					
					fileURL += "?start="+String(pointInTime);
					movableBars_mc.progressBar_mc.width = 0;
					player.play(fileURL);
					break;
					
					case Pyro.STREAM_TYPE_TRUE_STREAM:
					player.seek(pointInTime);
					break;
				}
			}
			else
			{
				if (player.streamType != Pyro.STREAM_TYPE_PROXIED_PROGRESSIVE)
					player.seek(pointInTime);
				else
					player.seek(pointInTime-player.timeOffset);
			
			}
				
		}
		
		private function movableBarsHandler(e:MouseEvent):void
		{
			switch(e.type)
			{
				case "rollOver":
					MovieClip(movableBars_mc.progressBar_mc).transform.colorTransform = new ColorTransform(0,0,0,0,255,153,0,255);
				break;
				case "rollOut":
					MovieClip(movableBars_mc.progressBar_mc).transform.colorTransform = new ColorTransform(0,0,0,0,185,185,185,255);
				break;
				
				case "mouseDown":
					/* var totalWidth:Number = movableBars_mc.backgroundBar_mc.width;
					var localX:Number = MovieClip(movableBars_mc.backgroundBar_mc).globalToLocal(new Point(e.localX, e.localY)).x+movableBars_mc.x;
					var pointInTime:Number = (localX * player.duration) / totalWidth;
					var pointIsBuffered:Boolean = pointInTime > player.timeOffset && localX < (movableBars_mc.bufferingBar_mc.width-movableBars_mc.progressMask_mc.x);
					
					if (player.streamType == Pyro.STREAM_TYPE_TRUE_STREAM)
					{	
						player.seek(pointInTime);
					}
					else 
						
					} */
				break;		
			}
		}
		
		public function tossForward():void
		{
			var totalWidth:Number = movableBars_mc.backgroundBar_mc.width;
			var tossAmount:Number = totalWidth * .05;
			
			var localX:Number = movableBars_mc.progressBar_mc.width + tossAmount;
			
			if (localX > totalWidth)
				localX = totalWidth;
			
			var pointInTime:Number = (localX * player.duration) / totalWidth;
			
			if (pointInTime - 1 < 0)
				pointInTime = 0;
			else
				pointInTime -= 1;
			
			if (player.streamType == Pyro.STREAM_TYPE_PROXIED_PROGRESSIVE) 		
				player.seek(pointInTime-player.timeOffset);
			else
				player.seek(pointInTime);
		}
		
		public function tossBackward():void
		{
			var totalWidth:Number = movableBars_mc.backgroundBar_mc.width;
			var tossAmount:Number = totalWidth * .05;
			
			var localX:Number = movableBars_mc.progressBar_mc.width - tossAmount;
			
			if (localX < 0)
				localX = .1;
			
			var pointInTime:Number = (localX * player.duration) / totalWidth;
			
			if (pointInTime - 1 < 0)
				pointInTime = 0;
			else
				pointInTime -= 1;
			
			if (player.streamType == Pyro.STREAM_TYPE_PROXIED_PROGRESSIVE) 		
				player.seek(pointInTime-player.timeOffset);
			else
				player.seek(pointInTime);
		}
		
		
		
		private function volumeButtonMD(evt:MouseEvent=null):void
		{
			lockUI(true, [volumeButton_mc]);
			lockUI(false, [volumeSlider_mc]);
			volumeSlider_mc.volume_slider_bg.useHandCursor = false;
			volumeSlider_mc.volumeMask_mc.mouseEnabled = false;
			volumeSliderOpened = true;	
			sliderOut = false;			
			volumeSlider_mc.visible = true;
			
			if (volumeSlider_mc.hasEventListener(MouseEvent.ROLL_OUT))
				volumeSlider_mc.removeEventListener(MouseEvent.ROLL_OUT, sliderMOut);
				
			volumeSlider_mc.addEventListener(MouseEvent.ROLL_OUT, sliderMOut, false, 0, true);
			
			if (volumeSlider_mc.sliderImage_mc.hasEventListener(MouseEvent.MOUSE_DOWN))
				volumeSlider_mc.sliderImage_mc.removeEventListener(MouseEvent.MOUSE_DOWN, sliderImageClicked);
				
			volumeSlider_mc.sliderImage_mc.addEventListener(MouseEvent.MOUSE_DOWN, sliderImageClicked, false, 0, true);
			
			if (volumeSlider_mc.sliderHandler_mc.hasEventListener(MouseEvent.MOUSE_DOWN))
				volumeSlider_mc.sliderHandler_mc.removeEventListener(MouseEvent.MOUSE_DOWN, sliderHandlerDown);
				
			volumeSlider_mc.sliderHandler_mc.addEventListener(MouseEvent.MOUSE_DOWN, sliderHandlerDown, false, 0, true);
			
			if (volumeSlider_mc.sliderHandler_mc.hasEventListener(MouseEvent.MOUSE_UP))
				volumeSlider_mc.sliderHandler_mc.removeEventListener(MouseEvent.MOUSE_UP, sliderHandlerUp);
				
			volumeSlider_mc.sliderHandler_mc.addEventListener(MouseEvent.MOUSE_UP, sliderHandlerUp, false, 0, true);
		}
		
		public function applyLockingOverlay(allowPlay:Boolean=false):void
		{
			MovieClip(overlay_mc).mouseEnabled = true;
			MovieClip(overlay_mc).alpha = .5;
			if (allowPlay)
			{
				lockUI(false, [this.playPauseButton_mc]);
				overlay_mc.x = this.playPauseButton_mc.x + this.playPauseButton_mc.width;
			} 
			else
			{
				overlay_mc.x = 0;
			}
		}
		
		public function removeLockingOverlay():void
		{
			MovieClip(overlay_mc).mouseEnabled = false;
			MovieClip(overlay_mc).alpha = 0;
			overlay_mc.x = 0;
		}
		
		private function sliderMOut(e:MouseEvent=null):void
		{
			sliderOut = true;
			
			if (!isDraggingVolume)
				closeVolumeSlider();
		
		}
		
		private function sliderImageClicked(evt:MouseEvent):void
		{
			MovieClip(volumeSlider_mc.sliderHandler_mc).y = MovieClip(volumeSlider_mc).mouseY;
			sliderMoved();
		} 
		
		private function sliderHandlerDown(evt:MouseEvent=null):void
		{
			MovieClip(volumeSlider_mc.sliderHandler_mc).startDrag(true, progressRectangle);	
			isDraggingVolume = true;
			
			stage.addEventListener(MouseEvent.MOUSE_MOVE, sliderMoved, false, 0, true);
			stage.addEventListener(MouseEvent.MOUSE_UP, sliderHandlerUp, false, 0, true);
		}
		
		private function sliderHandlerUp(evt:MouseEvent=null):void
		{
			MovieClip(volumeSlider_mc.sliderHandler_mc).stopDrag();
			isDraggingVolume = false;
			stage.removeEventListener(MouseEvent.MOUSE_UP, sliderHandlerUp);
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, sliderMoved);
			
			if (volumeSliderOpened && sliderOut)
			{
				closeVolumeSlider();
			}
			
			player.cookie.data['volume'] = player.volume;
			player.cookie.flush();
		}
		
		private function sliderMoved(evt:MouseEvent=null):void
		{
			var directY:Number = Math.floor(Number(progressRectangle.bottom) - MovieClip(volumeSlider_mc.sliderHandler_mc).y);
			var volumeFactor:Number = directY / Number(progressRectangle.height);
			volumeSlider_mc.volumeMask_mc.height = directY;
			player.volume = volumeFactor;
			volumeFactor <= 0 ? volumeSlider_mc.sliderHandler_mc.gotoAndStop(2) : volumeSlider_mc.sliderHandler_mc.gotoAndStop(1);
			evt.updateAfterEvent();	
		}
		
		
		override protected function removedFromStage(evt:Event=null):void
		{
			player.unregisterProgressCallback({name:this.name, funct:onProgress});
		}
		
		override protected function fullscreenHandler(evt:FullScreenEvent):void
		{
			var localWidth:Number;
			var localStr:String;
			localStr = subtitles.text;
			if (evt.fullScreen)
			{
					
				localWidth = stage.stageWidth;
				var FSsubtitlesTF = new TextFormat(core.mainFont.fontName, 25, 0xFFFFFF);
				FSsubtitlesTF.align = TextFormatAlign.CENTER;
				
				this.removeChild(subtitles);
				
				subtitles = new TextField();
				subtitles.defaultTextFormat = FSsubtitlesTF;
				
				subtitles.gridFitType = GridFitType.PIXEL;
				subtitles.antiAliasType = AntiAliasType.ADVANCED;
				subtitles.selectable = false;
				subtitles.embedFonts = true;
				subtitles.thickness = -100;
				subtitles.sharpness = 250;
				subtitles.mouseEnabled = false;
				addChild(subtitles);
				
				if (this.subtitlesOn)
				{
					subtitles.y = -38;
					subtitles.x = 1;
					subtitles.height = 70;
					background_mc.y = -40;
					background_mc.height = 87;
					player.height = stage.stageHeight-50;
					subtitles.text = localStr;
				}
			}
			else
			{
				this.removeChild(subtitles);
				subtitles = new TextField();
				subtitles.defaultTextFormat = subtitlesTF;
				
				subtitles.gridFitType = GridFitType.PIXEL;
				subtitles.antiAliasType = AntiAliasType.ADVANCED;
				subtitles.selectable = false;
				subtitles.embedFonts = true;
				subtitles.thickness = -100;
				subtitles.sharpness = 250;
				subtitles.mouseEnabled = false;
				
				addChild(subtitles);
				localWidth = core.requestedSizes.width;
				
				if (subtitlesOn)
				{
					subtitles.y = 2;
					subtitles.x = 1;
					subtitles.height = 34;
					background_mc.y = 0;
					background_mc.height = 37;
					subtitles.text = localStr;
					
				}
				else
				{
					subtitles.y = 70;
					subtitles.x = 1;
					background_mc.y = 0;
					background_mc.height = 37;
				
					subtitles.text = localStr;
				}
			}
			
			overlay_mc.width = localWidth;
			background_mc.width = localWidth;
			mask_mc.width = localWidth;
			positionHorizontals();
			setOptionals();
		}
		
		override protected function stageResized(evt:Event=null):void
		{
			var localWidth:Number;
			var localStr:String;
			localStr = subtitles.text;
			
			this.removeChild(subtitles);
			subtitles = new TextField();
			subtitles.defaultTextFormat = subtitlesTF;
			
			subtitles.gridFitType = GridFitType.PIXEL;
			subtitles.antiAliasType = AntiAliasType.ADVANCED;
			subtitles.selectable = false;
			subtitles.embedFonts = true;
			subtitles.thickness = -100;
			subtitles.sharpness = 250;
			subtitles.mouseEnabled = false;
			
			addChild(subtitles);
			localWidth = stage.stageWidth;
			
			if (localWidth < core.minimumWidth)
				localWidth = core.minimumWidth;
					
			if (subtitlesOn)
			{
				subtitles.y = 2;
				subtitles.x = 1;
				subtitles.height = 34;
				background_mc.y = 0;
				background_mc.height = 37;
				subtitles.text = localStr;
				
			}
			else
			{
				subtitles.y = 70;
				subtitles.x = 1;
				background_mc.y = 0;
				background_mc.height = 37;
			
				subtitles.text = localStr;
			}

			overlay_mc.width = localWidth;
			background_mc.width = localWidth;
			mask_mc.width = localWidth;
			positionHorizontals();
			setOptionals();
		}
		
		
		public function onProgress():void
		{
			var m:MovieClip = movableBars_mc;
			var offsetRatio:Number = 0;
			var localWidth:Number;
			
			var bufferRatio:Number = (player.bytesLoaded / player.bytesTotal);	
			
			if (player.duration > 0)
			{
				if (!this.bookmarksView.bookmarksDrawn)
					this.bookmarksView.reset();
			}	 
			
			if (player.timeOffset > 0 && player.streamType == Pyro.STREAM_TYPE_PROXIED_PROGRESSIVE)
			{
				var offsetX:Number = (player.timeOffset / player.duration) * m.backgroundBar_mc.width;
				localWidth = m.backgroundBar_mc.width - offsetX;
				m.progressBar_mc.x = m.bufferingBar_mc.x = offsetX;
				m.progressBar_mc.width = localWidth * player.rawTimeInfo.progressRatio;
				m.bufferingBar_mc.width = localWidth * player.loadRatio;
			}
			else
			{
				
				localWidth = m.backgroundBar_mc.width;
				m.progressMask_mc.x = 0;
				m.progressBar_mc.x = m.bufferingBar_mc.x = 0;
				m.progressMask_mc.width = localWidth;
				m.progressBar_mc.width = localWidth * player.progressRatio;
				m.bufferingBar_mc.width = localWidth * player.loadRatio;
			}
			
			leftTime_txt.text = player.formattedTime;
			rightTime_txt.text = player.formattedDuration;
			
			if (timeCheck != player.time)
			{
				timeCheck = player.time;	
				if (core.bufferingView.isRunning)
					core.bufferingView.stopModal();	
			}
			else
			{
				if (player.time > 0 && core.currentState != NFBPlayer.END_PLAYLIST_STATE 
				&& core.currentState != NFBPlayer.FILE_NOT_FOUND_STATE && core.currentState != NFBPlayer.MESSAGE_STATE
				&& core.currentState != NFBPlayer.MORE_INFOS_STATE && core.currentState != NFBPlayer.OPTIONS_STATE && core.currentState != NFBPlayer.SHARING_STATE
				&& player.status != Pyro.STATUS_PAUSED)
				{
					core.bufferingView.startChecking();
				}
			}
			
			
		}
		
		private function rotateArrow(evt:Event):void
		{
			MovieClip(playPauseButton_mc.bufferingIcon_mc).rotation -= 7;		
		}
		
		public function lockButtons(lock:Boolean=true):void
		{
			
			if (this.hasInfosButton)
			{
				
				
				if (this.hasBuyButton)
				{
					buttonsEnabledArray = [infosButton_mc, optionsButton_mc, descAudioButton_mc, closeCaptionsButton_mc, sharingButton_mc, cartButton_mc, smallLogoButton_mc, volumeButton_mc, fullscreenButton_mc];	
					cartButton_mc.visible = true;
				}
				else
				{
					buttonsEnabledArray = [infosButton_mc, optionsButton_mc, descAudioButton_mc, closeCaptionsButton_mc, sharingButton_mc, smallLogoButton_mc, volumeButton_mc, fullscreenButton_mc];	
					cartButton_mc.visible = false;
				}
			}
			else
			{
				if (this.hasBuyButton)
				{
					buttonsEnabledArray = [optionsButton_mc, descAudioButton_mc, closeCaptionsButton_mc, sharingButton_mc, cartButton_mc, smallLogoButton_mc, volumeButton_mc, fullscreenButton_mc];	
					cartButton_mc.visible = true;
				}
				else
				{
					buttonsEnabledArray = [optionsButton_mc, descAudioButton_mc, closeCaptionsButton_mc, sharingButton_mc, smallLogoButton_mc, volumeButton_mc, fullscreenButton_mc];
					cartButton_mc.visible = false;
				}
			}
			
			if (lock)
			{
				lockUI(true, buttonsEnabledArray);
			}
			else
			{
				lockUI(false, buttonsEnabledArray);
				this.setTrackOptions();
				this.setOptionals();
			}	
		}
		 
		override protected function streamStarted(evt:PyroEvent):void
		{
			
		}
		
		override protected function streamStatusUpdated(evt:StatusUpdateEvent):void
		{
			
			switch(evt.status)
			{
				case Pyro.STATUS_PLAYING:
				if (player.useFullScreen)
					this.setProperties([fullscreenButton_mc], {mouseEnabled:true, alpha:.7});
					
					
				this.removeLockingOverlay();
				
				MovieClip(playPauseButton_mc.pauseIcon_mc).visible = true;
				MovieClip(playPauseButton_mc.playIcon_mc).visible = false;
				MovieClip(playPauseButton_mc.bufferingIcon_mc).visible = false;
			
				if (MovieClip(playPauseButton_mc).hasEventListener(Event.ENTER_FRAME))
					MovieClip(playPauseButton_mc).removeEventListener(Event.ENTER_FRAME, rotateArrow);
				
				this.setProperties([movableBars_mc], {mouseEnabled:true, mouseChildren:true});
				
				if (core.currentState != NFBPlayer.PREVIEW_IMAGE_STATE)
				{
					lockButtons(false);
					this.removeLockingOverlay();
				}	
				else
				{
					lockButtons(true);	
				}
				
				
				break;
				
				case Pyro.STATUS_PAUSED:
				MovieClip(playPauseButton_mc.pauseIcon_mc).visible = false;
				MovieClip(playPauseButton_mc.playIcon_mc).visible = true;
				MovieClip(playPauseButton_mc.bufferingIcon_mc).visible = false;
				if (MovieClip(playPauseButton_mc).hasEventListener(Event.ENTER_FRAME))
					MovieClip(playPauseButton_mc).removeEventListener(Event.ENTER_FRAME, rotateArrow);
			
				if (core.currentState != NFBPlayer.PREVIEW_IMAGE_STATE)
				{
					lockButtons(false);
					this.removeLockingOverlay();
				}
				else
				{	
					lockButtons(true);
					
				}
				break;
				
				case Pyro.STATUS_PENDING:
				if (core.currentState != NFBPlayer.END_PLAYLIST_STATE && core.currentState != NFBPlayer.PREVIEW_IMAGE_STATE && core.currentState != NFBPlayer.FILE_NOT_FOUND_STATE) 
				{
					MovieClip(playPauseButton_mc.pauseIcon_mc).visible = false;
					MovieClip(playPauseButton_mc.playIcon_mc).visible = false;
					MovieClip(playPauseButton_mc.bufferingIcon_mc).visible = true;
					
					lockButtons(true);
					
						
					if (!MovieClip(playPauseButton_mc).hasEventListener(Event.ENTER_FRAME))
						MovieClip(playPauseButton_mc).addEventListener(Event.ENTER_FRAME, rotateArrow, false, 0, true);			
				}	
				break;	
			}
		}	
		
	
		override protected function coreStateUpdated(evt:Event=null):void 
		{ 
			switch (core.currentState)
			{
				case NFBPlayer.PREVIEW_IMAGE_STATE:
				lockButtons(false);
				this.removeLockingOverlay();
				lockUI(false, [playPauseButton_mc]);
				this.setProperties([fullscreenButton_mc], {mouseEnabled:false, alpha:.3});
				this.setProperties([movableBars_mc], {mouseEnabled:false, mouseChildren:false});
				break;
				
				case NFBPlayer.MESSAGE_STATE:
				lockButtons(true);
				
				break;
				
				case NFBPlayer.SHARING_STATE:
				case NFBPlayer.OPTIONS_STATE:
				case NFBPlayer.MORE_INFOS_STATE:
				if (!core.overlayedPanelOpen)
				{
					core.overlayedPanelOpen = true;
					if (player.status != Pyro.STATUS_PAUSED)
						core.wasPaused = false;
					else
						core.wasPaused = true;
					
					if (player.status == Pyro.STATUS_PLAYING)
						player.pause();
				}
				
				lockButtons(true);
				lockUI(false, [infosButton_mc, optionsButton_mc, sharingButton_mc, fullscreenButton_mc]);	
				lockUI(true, [playPauseButton_mc]);
				if (core.moreInfoView.endPlaylistOn || core.sharingView.endPlaylistOn)
					lockUI(true, [optionsButton_mc]);
				break;
			
				case NFBPlayer.END_PLAYLIST_STATE:
				MovieClip(playPauseButton_mc.pauseIcon_mc).visible = false;
				MovieClip(playPauseButton_mc.playIcon_mc).visible = true;
				MovieClip(playPauseButton_mc.bufferingIcon_mc).visible = false;
				lockButtons(true);
				// this.applyLockingOverlay(true);
				lockUI(false, [playPauseButton_mc, infosButton_mc, sharingButton_mc, fullscreenButton_mc, optionsButton_mc, volumeButton_mc]);
				this.setProperties([movableBars_mc], {mouseEnabled:false, mouseChildren:false});
				break;
			
				case NFBPlayer.DEFAULT_STATE:
				default:
				lockButtons(false);
				lockUI(false, [playPauseButton_mc]);
				this.removeLockingOverlay();			
				break;
				
				case NFBPlayer.FILE_NOT_FOUND_STATE:
				lockButtons(true);
				lockUI(true, [playPauseButton_mc]);
				MovieClip(playPauseButton_mc.pauseIcon_mc).visible = false;
				MovieClip(playPauseButton_mc.playIcon_mc).visible = true;
				MovieClip(playPauseButton_mc.bufferingIcon_mc).visible = false;
				if (!MovieClip(playPauseButton_mc).hasEventListener(Event.ENTER_FRAME))
						MovieClip(playPauseButton_mc).addEventListener(Event.ENTER_FRAME, rotateArrow, false, 0, true);
				break;
			}
		}
		
		override protected function streamCompleted(evt:PyroEvent):void
		{
			if (player.streamType != Pyro.STREAM_TYPE_PROXIED_PROGRESSIVE)
			{
				player.seek(0);
				player.pause();
			}
			else
			{
				if (player.timeOffset == 0)
				{
					player.seek(0);
					player.pause();
				}
			}	
			MovieClip(playPauseButton_mc.pauseIcon_mc).visible = false;
			MovieClip(playPauseButton_mc.playIcon_mc).visible = true;
		}
		
		
	}
}